package com.zzyl.controller;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.DeptDto;
import com.zzyl.dto.PostDto;
import com.zzyl.dto.ResourceDto;
import com.zzyl.service.ResourceService;
import com.zzyl.vo.DeptVo;
import com.zzyl.vo.PostVo;
import com.zzyl.vo.ResourceVo;
import com.zzyl.vo.TreeVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@Api(tags = "资源管理")
@RestController
@RequestMapping("/resource")
public class ResourceController {
    @Autowired
    ResourceService resourceService;

    /***  多条件查询资源列表* @param resourceDto 资源DTO对象* @return List<DeptVo>*/
    @PostMapping("/list")
    @ApiOperation(value = "资源列表",notes = "资源列表")
    @ApiImplicitParam(name = "resourceDto",value = "资源DTO对象",required = true,dataType = "ResourceDto")
    public ResponseResult<List<ResourceVo>> resourceList(@RequestBody ResourceDto resourceDto) {

        List<ResourceVo> resourceVoList = resourceService.resourceList(resourceDto);
        return ResponseResult.success(resourceVoList);
    }

    /**  资源部门树形* @return*/
    @PostMapping("/tree")
    @ApiOperation(value = "资源树形",notes = "资源树形")
    public ResponseResult<TreeVo> resourceTreeVo(@RequestBody ResourceDto resourceDto) {
        TreeVo treeVo = resourceService.resourceTreeVo(resourceDto);
        return ResponseResult.success(treeVo);
    }


    /***  新增资源(功能)* @param resourceDto 岗位DTO对象* @return ResourceDto*/
    @PutMapping
    @ApiOperation(value = "资源添加",notes = "资源添加")
    public ResponseResult<ResourceVo> insertRe(@RequestBody ResourceDto resourceDto){
        Boolean p = resourceService.insertRe(resourceDto);/*因为响应结果是true,所以是Boolean*/
        return ResponseResult.success(p);
    }

    @PostMapping("/enable")
    @ApiOperation(value = "启用-禁用",notes = "启用-禁用")
    public ResponseResult<Boolean> isEnable(@RequestBody ResourceDto resourceDto){
        return ResponseResult.success(resourceService.isEnable(resourceDto));

    }
    @PatchMapping
    @ApiOperation(value = "资源修改",notes = "资源修改")
    public ResponseResult<Boolean> updateResource(@RequestBody ResourceDto resourceDto){
       /*因为响应结果是true,所以是Boolean*/
        return ResponseResult.success(resourceService.updateResource(resourceDto));
    }
}
